<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
			<el-form-item label="工器具名称" prop="materialName">
				<el-input v-model="queryParams.materialName" placeholder="请输入工器具名称" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-table v-loading="loading" :data="elecMaterialList">
			<el-table-column label="工器具名称" align="center" prop="materialName" />
			<el-table-column label="库房" align="center" prop="warehouseName" />
			<el-table-column label="在库数" align="center" prop="inNum" width="150" />
			<el-table-column label="出库数" align="center" prop="outNum" width="150" />
			<el-table-column label="总数量" align="center" prop="stockNum" width="150"/>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
		 @pagination="getList" />
	</div>
</template>

<script>
	import {
		listElecMaterial,
		getElecMaterial,
		delElecMaterial,
		addElecMaterial,
		updateElecMaterial,
		listWarehouseOptions,
		listSortOptions,
		listCabinetOptions,
		listBasGridOptions,
		listProviderOptions,
		listUnitOptions,
		selectElecMaterialWarehouseList
	} from "@/api/elec/elecMaterial";
	import Treeselect from "@riophae/vue-treeselect";
	import "@riophae/vue-treeselect/dist/vue-treeselect.css";

	export default {
		name: "ElecMaterial",
		dicts: ['material_status', 'spare_part_type'],
		components: {
			Treeselect
		},
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 工器具表格数据
				elecMaterialList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					materialCategory: '1',
					materialCode: null,
					materialName: null,
					materialStatus: null,
					sortId: null,
					warehouseId: null,
					providerId: null,
				},
				// 查询参数
				queryCabinetParams: {
					warehouseId: null,
				},
				// 查询参数
				queryGridParams: {
					cabinetId: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {
					materialCode: [{
						required: true,
						message: "工器具编码不能为空",
						trigger: "blur"
					}],
					materialName: [{
						required: true,
						message: "工器具名称不能为空",
						trigger: "blur"
					}],
					sortId: [{
						required: true,
						message: "分类不能为空",
						trigger: "change"
					}],
					warehouseId: [{
						required: true,
						message: "库房不能为空",
						trigger: "change"
					}],
					cabinetId: [{
						required: true,
						message: "柜架不能为空",
						trigger: "change"
					}],
					gridId: [{
						required: true,
						message: "层格不能为空",
						trigger: "change"
					}],
				},
				disabled: false,
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询工器具列表 */
			getList() {
				this.loading = true;
				selectElecMaterialWarehouseList(this.queryParams).then(response => {
					this.elecMaterialList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					materialId: null,
					materialCode: null,
					materialName: null,
					materialStatus: null,
					specifications: null,
					sortId: null,
					warehouseId: null,
					cabinetId: null,
					gridId: null,
					unitId: null,
					providerId: null,
					materialCategory: null,
					purchaseDate: null,
					inDate: null,
					preRepairDate: null,
					repairCycle: null,
					serviceLife: null,
					rfidCode: null,
					singleWeight: null,
					totalWeight: null,
					sparePartType: null,
					remark: null,
					delFlag: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
		}
	};
</script>
